﻿using Apex.Infrastructure.EFCore;
using MediatR;
using Microsoft.EntityFrameworkCore;

namespace TaskMasterByQuartz.Infrastructure.DbContext
{
    public class MyDbContext : BaseDbContext
    {

        public MyDbContext(DbContextOptions<MyDbContext> options, IMediator mediator)
            : base(options, mediator)
        {
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            // https://github.com/yangzhongke/Zack.EFCore.Batch/blob/main/README_CN.md
            // 批量增删改
            optionsBuilder.UseBatchEF_MSSQL();
            // 如果在外部没有配置，就在这里配置数据库连接信息
            if (!optionsBuilder.IsConfigured)
            {
                //optionsBuilder.UseNpgsql(_connectionString);
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.ApplyConfigurationsFromAssembly(GetType().Assembly);
            modelBuilder.EnableSoftDeletionGlobalFilter();
        }
    }
}
